package com.qf.service.caiwu_service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Account;
import com.qf.bean.PrefundRule;
import com.qf.dao.caiwu_dao.AccountMapper;
import com.qf.service.caiwu_service.AccountService;
import com.qf.utils.caiwu.enums.AccountCheckStateEnum;
import com.qf.utils.caiwu.enums.AccountTradeStateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 2019/12/11 0011
 * Author->DT
 * sassspringboot
 * 行到水穷处 坐看云起时
 * 模块：
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountMapper;

    //删除账目信息
    @Override
    public int deleteByPrimaryKey(Integer aid) {
        return accountMapper.deleteByPrimaryKey(aid);
    }

    @Override
    public int insertSelective(Account record) {
        record.setRecorder("管理员");
        record.setRecordeTime(new Date());
        record.setCheckState(AccountCheckStateEnum.BEFORE.getState());
        record.setTradeState(AccountTradeStateEnum.AFTER.getState());
        return accountMapper.insertSelective(record);
    }

    @Override
    public PageInfo<Account> findAccountListByLimit(Map map) {
        //开启分页
        PageHelper.startPage((int)map.get("index"),(int)map.get("page"));
        //查询账目信息列表
        List<Account> list=accountMapper.findAccountList(map);
        //封装PageInfo
        return new PageInfo<>(list);
    }

    @Override
    public Account selectByPrimaryKey(Integer aid) {
        //查询指定id的账目信息
        return accountMapper.selectByPrimaryKey(aid);
    }

    //编辑账目信息
    @Override
    public int updateByPrimaryKeySelective(Account record) {
        return accountMapper.updateByPrimaryKeySelective(record);
    }

    //审核
    @Override
    public int checkStateToChecked(Integer aid) {
        return accountMapper.checkStateToChecked(aid);
    }

    //确认
    @Override
    public int tradeStateToAffirm(Integer aid) {
        return accountMapper.tradeStateToAffirm(aid);
    }

    //查询被选中id的用户信息
    @Override
    public List<Account> findByIds(Integer[] aid) {
        return accountMapper.findByIds(aid);
    }

    //批量删除
    @Override
    public int deleteChecked(Integer[] aid) {
        return accountMapper.deleteChecked(aid);
    }
}
